import numpy as np
import matplotlib.pyplot as plt
temperature_str = np.loadtxt('demo.csv',delimiter=',',skiprows=1,usecols=(1),unpack=False,dtype=bytes)
temperature = np.ndarray(len(temperature_str))
def queshe(temperature_str):

    for index in range(0, len(temperature_str)):
        item = temperature_str[index]
        if item != b'':
            item = item.decode('gb2312')
            item = float(item)

        else:
            item = None
        temperature[index] = item

def yichang(temperature):
    for index in range(len(temperature)):
        item = temperature[index]
        if item >= 500.0:
            item = None
        temperature[index] = item

def bisec(dataArray):
    for index in range(0,len(dataArray)):
        if np.isnan(dataArray[index]):
            dataArray[index]=0.5*(dataArray[index-1]+dataArray[index+1])

queshe(temperature_str)   #失值函数
yichang(temperature)#异常函数
bisec(temperature)#函数处理


# print(temperature)
t = np.arange(len(temperature))
plt.plot(t,temperature)
plt.plot(t,temperature,'pr')
plt.show()
np.savetxt('ug_demo.csv',temperature,delimiter=',',fmt='%.2f')
